import axios from '@/utils/request'
import { setToken } from '@/utils/storage'
import { LOGIN } from '../constants'
import { removeToken } from '@/utils/storage'
import { LOG_OUT } from '../constants'
export const login = (values) => {
  return async (dispatch) => {
    const res = await axios({
      method: 'post',
      url: '/authorizations',
      data: values,
    })
    // 存储token
    const token = res.data.data.token
    setToken(token)
    dispatch({ type: LOGIN, payload: token })
  }
}

export function logOut() {
  return (dispatch) => {
    dispatch({
      type: LOG_OUT,
    })
    removeToken()
  }
}
